﻿@{
    ViewData["Title"] = "LogManagement";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<div>
    <button onclick="AddLogInfo('测试')">测试日志添加</button>
    <div style="margin:60px 60px">
       
        <table>
            <tr>
                <td>
                    操作日期
                    <div class="layui-input-inline layui-input-wrap">
                        <div class="layui-input-prefix">
                            <i class="layui-icon layui-icon-date"></i>
                        </div>
                        <input type="text" name="OperationTime" id="SOperationTime" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                    </div>
                    @* <input type="date" id="SOperationTime" /> *@
                    &emsp;&emsp;
                         
                </td>
                <td>
                    <div class="layui-input-inline layui-input-wrap">
                        <div class="layui-input-prefix">
                            <i class="layui-icon layui-icon-date"></i>
                        </div>
                        <input type="text" name="OperationTime" id="EOperationTime" lay-verify="date" placeholder="yyyy-MM-dd" autocomplete="off" class="layui-input">
                    </div>
                    @* <input type="date" id="EOperationTime" /> *@
                    &emsp;&emsp;


                </td>
            
                <td>
                    <div class="layui-input-inline layui-input-wrap">
                        <label class="layui-form-label">操作人</label>
                        <div class="layui-input-block">
                            <input type="text" id="Name" name="username" lay-verify="required" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    @* <input type="text" class="layui-input" id="Name"> &emsp;&emsp; *@

                </td>
                <td>
                    <button type="button" class="layui-btn layui-btn-primary" id="sea2rchBtn" onclick="getListData(1)">
                       
                        <i class="layui-icon"></i> 搜 索
                    </button>

                </td>
            </tr>
        </table>



        @*     <div class="layui-inline">
        <button type="button" class="layui-btn" onclick="onAddBtn()">增加功能</button>
        </div>

        <div class="layui-inline">
        <a class="layui-btn layui-btn-danger layui-btn-normal delAll_btn">批量删除</a>
        </div> *@

        <table id="ID-table-demo-setRowChecked"></table>

        <div id="pagesbox"></div>

        <!--添加的弹出层-->
        <div id="add-main" style="display: none;">
            <div>
                <div style="float:left;margin-left:20px">
                    <span id="Id" style="display:none"></span>
                    <label id="BindId">menuName</label>
                </div>
                @* <label id="newid">newmenuName</label> *@
                <div style="float:left;margin-left:20px" id="ID-tree-demo-showCheckbox"></div>

                <input type="hidden" name="permissionId" />
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="saves">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary" id="closeBtn">重置</button>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <div id="add-main" style="display:none">
        asdfe
    </div>
    </div>

    
<script type="text/html" id="barDemo">
    <div class="layui-btn-container">
        @*  <a class="layui-btn layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit">修改</i></a> *@
          @* <button type="button" class="layui-btn layui-btn-primary" lay-on="test-page" id="onAddInfo" lay-event="onAddInfo" style="background-color:green;color:black">添加</button> *@
    </div>

</script>    
<script src="~/layui/jquery-3.3.1.js"></script>
<script>

    layui.use(['table', 'laypage', 'layer', 'form', 'laydate'], function () {
        var table = layui.table;
        var laypage = layui.laypage;
        var $ = layui.jquery;
        var form = layui.form;
        var layer = layui.layer; // 添加layui弹出层模块
        var laydate = layui.laydate;
        laydate.render({
            elem: '#SOperationTime',
        });
        laydate.render({
            elem: '#EOperationTime',
        });



        //$('#onAddinfo').on('click', function () {
        //    alert("dsa")
        //    // 批量事件
        //    layer.open({
        //        type: 1, // page 层类型
        //        area: ['1200px', '800px'],
        //        title: '新增事件类型',
        //        shade: 0,//控制遮罩
        //        shadeClose: true, // 点击遮罩区域，关闭弹层
        //        maxmin: true, // 允许全屏最小化
        //        anim: 0, // 0-6 的动画形式，-1 不开启
        //        content: $("#add-main"),
        //    });
        //});
        table.on('tool(barDemo)', function (obj) {
            var data = obj.data;
            $("#onAddInfo").on('click', function () {
                alert(1);
                if (obj.event == 'onAddInfo') {
                    layer.open({
                        type: 1, // page 层类型
                        area: ['1200px', '800px'],
                        title: '新增事件类型',
                        shade: 0,//控制遮罩
                        shadeClose: true, // 点击遮罩区域，关闭弹层
                        maxmin: true, // 允许全屏最小化
                        anim: 0, // 0-6 的动画形式，-1 不开启
                        content: $("#add-main"),
                    });
                }
            })


        });






        var checkedIds = []; // 存储选中节点的 id
        var checkedIdsAll = [];


        // 单删除
        function deleteData(id) {
            $.ajax({
                url: `http://8.140.245.229:8000/WorkBench/api/Log/DelLog?Id=${id}`,
                type: 'get',
                headers: {
                    'Authorization': "Bearer " + localStorage["token"] + ""
                },
                success: function (res) {
                    if (res > 0) {
                        //layer.msg('删除成功');
                        layer.msg("删除成功");
                        getListData(1);
                        //window.location.href = "/Material/PurchaseShow";
                    } else {
                        layer.msg("删除失败");
                        //layer.msg('删除失败');
                    }
                },
                error: function () {
                    layer.msg('删除请求失败');

                }
            });

        }



        // 监听工具条，实现删除功能
        table.on('tool(ID-table-demo-setRowChecked)', function (obj) {
            var data = obj.data;
            if (obj.event == 'delete') {
                layer.confirm('确定删除吗？', function (index) {
                    deleteData(data.Id); // 传递正确的数据项ID
                    layer.close(index);
                });
            }
            else if (obj.event == 'edit') {
                location.href = `/T_vehicle/TireUsageUpdate?TiresUsedId=${data.Id}`;
            }
        });
        $(function () {
            // 初始化加载数据
            getListData(1);
        })
    });
    var $ = layui.jquery;

    var pageSize = 15; // 每页显示条数
    //获取列表  显示
    function getListData(pageIndex) {
        //获取查询条件


        //ajax后台交互
        $.ajax({
            //http://8.140.245.229:8000/AuthorizationPeopleGetRout/api
            url: 'http://8.140.245.229:8000/WorkBenchRead/api/LOG/AddLog',
            type: 'get',
            dataType: 'json',
            //参数
            data: {
                PageIndex: pageIndex,
                PageSize: pageSize,
                SOperationTime: $("#SOperationTime").val(),
                EOperationTime: $("#EOperationTime").val(),
                Operator: $("#Name").val(),
            },
            success: function (res) {
                var i = 0;
                //渲染表格数据
                layui.use(['table', 'laypage'], function () {
                    var table = layui.table;
                    var laypage = layui.laypage;
                    console.log(res)
                    table.render({
                        //挂载的表格id
                        elem: '#ID-table-demo-setRowChecked',
                        cols: [[
                            {
                                field: 'Id', title: '序号', width: 120, align: 'center'
                              
                            },
                            { field: 'LogNumber', title: '日志编号', width: 120, align: 'center' },
                            {
                                field: 'OperationTime', title: '操作时间', width: 120, align: 'center',
                                templet: function (data) { return data.OperationTime.substring(0, 16).replace("T", " ") }
                            },
                            { field: 'Operator', title: '操作人', width: 120, align: 'center' },
                            { field: 'OlContext', title: '操作内容', width: 120, align: 'center' },
                            { title: '操作', width: 150, align: 'center', templet: '#barDemo', fixed: 'right', unresize: true },

                        ]],
                        toolbar: '#demo-toolbar-setRowChecked',
                        initSort: { // 设置初始排序
                            field: 'experience', // 字段名
                            type: 'asc' // 倒序
                        },
                        data: res.list
                    });

                    //分页

                    laypage.render({
                        //挂载的分页id
                        elem: 'pagesbox',
                        count: res.TotalCount,
                        limit: pageSize,
                        curr: pageIndex,
                        layout: ['count', 'prev', 'page', 'next', 'skip'],
                        jump: function (obj, first) {
                            if (!first) {
                                getListData(obj.curr);
                            }
                        }
                    });


                });
            }
        });
    }



    $('#searchBtn').on('click', function () {
        getListData(1);
    });


    //第一个参数为操作内容，例如：登录了系统，修改/删除/添加/查询了日志表（或其他表，每次调用根据进行的操作写）
    //第二个参数为修改专用，将修改前的参数转为json字符串格式传入
    //第三个参数是将添加或删除的数据转为json传入，若是修改方法则把修改后的数据转为json字符串传入
    function AddLogInfo(OperationalContext, PreOperation, AfterOperation) {
        const data = {
            olContext: OperationalContext,
            PreOperation: PreOperation,
            AfterOperation: AfterOperation
        };
        // alert(JSON.stringify(data));
        $.ajax({
            url: "http://8.140.245.229:8000/WorkBench/api/Log/AddLog",
            type: 'post',
            dataType: 'json',
            headers: {
                'Authorization': "Bearer " + localStorage["token"] + ""
            },
            contentType: 'application/json', // 添加正确的 Content-Type 头部
            data: JSON.stringify(data),
            success: function (res) {
                // alert(res)
                getListData(1);
                console.log(res)
            }
        })
    }




</script>







